package com.aijk.web.admin.controller.ehm.question;

import com.aijk.commons.utils.Utils;
import com.aijk.ehm.api.EhmCompanyApi;
import com.aijk.ehm.api.EhmProblemLogApi;
import com.aijk.ehm.api.EhmProblemRecordApi;
import com.aijk.ehm.api.EhmResidentApi;
import com.aijk.ehm.model.EhmProblemLog;
import com.aijk.ehm.model.EhmProblemRecord;
import com.aijk.ehm.model.qo.EhmCompanyQo;
import com.aijk.ehm.model.qo.EhmProblemLogQo;
import com.aijk.ehm.model.qo.EhmProblemRecordQo;
import com.aijk.ehm.model.qo.EhmResidentQo;
import com.aijk.ehm.model.vo.EhmCompanyVo;
import com.aijk.ehm.model.vo.EhmResidentVo;
import com.aijk.web.admin.RetMsg;
import com.aijk.web.admin.controller.BaseController;
import com.aijk.web.admin.entity.ext.QuestionExt;
import com.aijk.web.admin.entity.ext.QuestionExtInfo;
import com.aijk.web.admin.utils.DataTableUtil;
import com.aijk.web.admin.utils.PdfUtils;
import com.aijk.web.admin.utils.QuestionUtils;
import com.github.pagehelper.PageInfo;
import com.google.gson.Gson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


@Controller
@RequestMapping("/admin/ehm/question")
public class QuertionController extends BaseController {
    protected Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private EhmProblemLogApi ehmProblemLogApi;

    @Autowired
    private EhmProblemRecordApi ehmProblemRecordApi;

    @Autowired
    private EhmCompanyApi ehmCompanyApi;

    @Autowired
    private EhmResidentApi ehmResidentApi;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public String list_view(Model model) {
        if(isSubCompany()) {
            if (isCompany()) {
                return "error/no_permissions";
            }
        }
        return "ehm/question/list";
    }

    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public RetMsg list(@RequestParam HashMap skey, @RequestParam(value = "draw", defaultValue = "1") Integer draw) {
        Long iTotalRecords;
        DataTableUtil.FormatOptions(skey);
        EhmProblemLogQo qo = DataTableUtil.fillQo(skey,EhmProblemLogQo.class);
        draw += 1;
        qo.setRidIsNull("1");
        PageInfo<EhmProblemLog> pageInfo = ehmProblemLogApi.page(qo);

        EhmProblemLogQo ehmProblemLogQo = new EhmProblemLogQo();
        ehmProblemLogQo.setRidIsNotNull("1");
        if(isSubCompany()){
            ehmProblemLogQo.setCompanyId(getCurrentUser().getCompanyId());
        }
        List<EhmProblemLog> logList = ehmProblemLogApi.list(ehmProblemLogQo);

        if(pageInfo.getList()!=null){
            for (EhmProblemLog ehmProblemLog : pageInfo.getList()){
                if(logList!=null && logList.size()>0){
                    ehmProblemLog.setQuestionNO(logList.size());
                }else{
                    ehmProblemLog.setQuestionNO(0);
                }
            }
        }
        iTotalRecords =pageInfo.getTotal();
        RetMsg regMsg = new RetMsg();
        regMsg.put("data", pageInfo.getList());
        regMsg.put("draw", draw);
        regMsg.put("recordsTotal", iTotalRecords);
        regMsg.put("recordsFiltered", iTotalRecords);
        return regMsg;
    }

    @RequestMapping(value = "/people/list", method = RequestMethod.GET)
    public String list_view1(Model model) {
        if(isSubCompany()){
            model.addAttribute("sys_flag" , true);
        }
        return "ehm/question/people_list";
    }

    @RequestMapping(value = "/people/list", method = RequestMethod.POST)
    @ResponseBody
    public RetMsg list1(@RequestParam HashMap skey, @RequestParam(value = "draw", defaultValue = "1") Integer draw) {
        Long iTotalRecords;
        DataTableUtil.FormatOptions(skey);
        EhmResidentQo qo = DataTableUtil.fillQo(skey,EhmResidentQo.class);
        draw += 1;

        if(skey.containsKey("question") && skey.get("question") !=null && !skey.get("question").equals("")){
            if(skey.containsKey("content") && skey.get("content") !=null && !skey.get("content").equals("")){
                if(skey.get("question").equals("1")){
                    qo.setTitle(skey.get("content")+"");
                }else if(skey.get("question").equals("2")){
                    EhmCompanyQo ehmCompanyQo = new EhmCompanyQo();
                    ehmCompanyQo.setTitle(skey.get("content")+"");
                    List<EhmCompanyVo> ehmCompanyVoList = ehmCompanyApi.list(ehmCompanyQo);
                    List<Long> companyIds = new ArrayList<>();
                    if(ehmCompanyVoList != null && ehmCompanyVoList.size() > 0){
                        for (EhmCompanyVo vo : ehmCompanyVoList){
                            companyIds.add(vo.getId());
                        }
                    }else{
                        companyIds.add((long)-1);
                    }
                    qo.setInCompanyId(companyIds);
                }else if(skey.get("question").equals("3")){
                    qo.setWorkno(skey.get("content")+"");
                }
            }
        }
        List<Long> ids = new ArrayList<>();
        EhmProblemLogQo ehmProblemLogQo = new EhmProblemLogQo();
        if(isSubCompany()){
            ehmProblemLogQo.setCompanyId(getCurrentUser().getCompanyId());
        }
        ehmProblemLogQo.setRidIsNotNull("1");
        List<EhmProblemLog> ehmProblemLogList = ehmProblemLogApi.list(ehmProblemLogQo);
        HashMap<Long , EhmProblemLog> logHashMap = new HashMap<>();
        if(ehmProblemLogList!=null && ehmProblemLogList.size() > 0){
            for (EhmProblemLog logs : ehmProblemLogList){
                if(logs.getRid()!=null){
                    ids.add(logs.getRid());
                    logHashMap.put(logs.getRid() , logs);
                }
            }
        }else{
            ids.add((long)-1);
        }
        qo.setInIds(ids);
        PageInfo<EhmResidentVo> pageInfo = ehmResidentApi.page(qo);

        if(pageInfo.getList()!=null)
            for (EhmResidentVo vo: pageInfo.getList()){
                if(logHashMap.containsKey(vo.getId())){
                    EhmProblemLog log = logHashMap.get(vo.getId());
                    vo.setLogTime(log.getCreated());
                    vo.setLogTitle(log.getProblemTitle());
                }
            }

        iTotalRecords =pageInfo.getTotal();
        RetMsg regMsg = new RetMsg();
        regMsg.put("data", pageInfo.getList());
        regMsg.put("draw", draw);
        regMsg.put("recordsTotal", iTotalRecords);
        regMsg.put("recordsFiltered", iTotalRecords);
        return regMsg;
    }

    /**
     * 问卷题目
     * @param model
     * @return
     */
    @RequestMapping(value = "/qs/edit", method = RequestMethod.GET)
    public String add_view(Model model , Long id , Integer type) {
        if(id!=null){
            EhmProblemLogQo ehmProblemLogQo = new EhmProblemLogQo();
            ehmProblemLogQo.setRid(id);
            List<EhmProblemLog> ehmProblemLogList = ehmProblemLogApi.list(ehmProblemLogQo);
            if(ehmProblemLogList != null && ehmProblemLogList.size() > 0){
                EhmProblemRecordQo ehmProblemRecordQo = new EhmProblemRecordQo();
                ehmProblemRecordQo.setRid(ehmProblemLogList.get(0).getRid());
                ehmProblemRecordQo.setCompanyId(ehmProblemLogList.get(0).getCompanyId());
                List<EhmProblemRecord> ehmProblemRecordList = ehmProblemRecordApi.list(ehmProblemRecordQo);
                QuestionExt ext = converModel(ehmProblemRecordList);
                List<String> stringList = new ArrayList<>();
                if(ext!=null&&ext.getQx()!=null  ){
                    model.addAttribute("list1" , ext.getQx());
                }else{
                    model.addAttribute("list1" , stringList);
                }
                if(ext!=null&&ext.getJkcj()!=null  ){
                    model.addAttribute("list2" , ext.getJkcj());
                }else{
                    model.addAttribute("list2" , stringList);
                }
                if(ext!=null&&ext.getLjzs()!=null  ){
                    model.addAttribute("list3" , ext.getLjzs());
                }else {
                    model.addAttribute("list3" , stringList);
                }
                model.addAttribute("question" , converModel(ehmProblemRecordList));
            }
            model.addAttribute("sys_flag",true);
        }else{
            model.addAttribute("sys_flag",false);
        }

        if(type!=null && type==1){
            model.addAttribute("sys_flag",false);
        }
        return "ehm/question/info_edit";
    }

    /**
     * 问卷统计
     * @param model
     * @return
     */
    @RequestMapping(value = "/tz/edit", method = RequestMethod.GET)
    public String add_view1(Model model,Long companyId) {
        EhmProblemLogQo ehmProblemLogQo = new EhmProblemLogQo();
        ehmProblemLogQo.setRidIsNotNull("1");
        //如果是企业端
        if(isSubCompany()){
            ehmProblemLogQo.setCompanyId(getCurrentUser().getCompanyId());
            model.addAttribute("sys_flag" , true);
        }else{
            EhmCompanyQo ehmCompanyQo = new EhmCompanyQo();
            ehmCompanyQo.setStatus((byte)10);
            List<EhmCompanyVo> ehmCompanyVoList = ehmCompanyApi.list(ehmCompanyQo);
            model.addAttribute("company" , ehmCompanyVoList);
            if(companyId!=null){
                ehmProblemLogQo.setCompanyId(companyId);
                model.addAttribute("companyId" , companyId);
                model.addAttribute("sys_flag" , false);
            }else{
                model.addAttribute("sys_flag" , false);
            }
        }
        List<EhmProblemLog> ehmProblemLogList = ehmProblemLogApi.list(ehmProblemLogQo);
        if(ehmProblemLogList != null && ehmProblemLogList.size() > 0) {
            List<Long> inIds = new ArrayList<>();
            for (EhmProblemLog log : ehmProblemLogList){
                inIds.add(log.getId());
            }
            EhmProblemRecordQo ehmProblemRecordQo = new EhmProblemRecordQo();
            ehmProblemRecordQo.setInPid(inIds);
            List<EhmProblemRecord> ehmProblemRecordList = ehmProblemRecordApi.list(ehmProblemRecordQo);
            List<QuestionExtInfo> questionExtInfoList = converListModel(ehmProblemRecordList , ehmProblemLogList.size());
            model.addAttribute("count" , ehmProblemLogList.size());
            model.addAttribute("data" , new Gson().toJson(questionExtInfoList));
        }else{
            List<QuestionExtInfo> questionExtInfoList = converListModel(null , 0);
            model.addAttribute("data" , new Gson().toJson(questionExtInfoList));
            model.addAttribute("count" , 0);
        }
        return "ehm/question/statistics_edit";
    }

    /**
     * 问卷统计
     * @param model
     * @return
     */
    @RequestMapping(value = "/tz/lb/edit", method = RequestMethod.GET)
    public String add_view2(Model model,Long companyId) {
        EhmProblemLogQo ehmProblemLogQo = new EhmProblemLogQo();
        ehmProblemLogQo.setRidIsNotNull("1");
        if(isSubCompany()){
            ehmProblemLogQo.setCompanyId(getCurrentUser().getCompanyId());
            model.addAttribute("sys_flag" , true);
        }else{
            EhmCompanyQo ehmCompanyQo = new EhmCompanyQo();
            ehmCompanyQo.setStatus((byte)10);
            List<EhmCompanyVo> ehmCompanyVoList = ehmCompanyApi.list(ehmCompanyQo);
            model.addAttribute("company" , ehmCompanyVoList);
            if(companyId!=null){
                ehmProblemLogQo.setCompanyId(companyId);
                model.addAttribute("companyId" , companyId);
                model.addAttribute("sys_flag" , false);
            }else{
                model.addAttribute("sys_flag" , false);
            }
        }
        List<EhmProblemLog> ehmProblemLogList = ehmProblemLogApi.list(ehmProblemLogQo);
            if(ehmProblemLogList != null && ehmProblemLogList.size() > 0) {
                List<Long> inIds = new ArrayList<>();
                for (EhmProblemLog log : ehmProblemLogList){
                    inIds.add(log.getId());
                }
                EhmProblemRecordQo ehmProblemRecordQo = new EhmProblemRecordQo();
                ehmProblemRecordQo.setInPid(inIds);
                List<EhmProblemRecord> ehmProblemRecordList = ehmProblemRecordApi.list(ehmProblemRecordQo);
                List<QuestionExtInfo> questionExtInfoList = converListModel(ehmProblemRecordList , ehmProblemLogList.size());
                model.addAttribute("count" , ehmProblemLogList.size());
                model.addAttribute("data" , new Gson().toJson(questionExtInfoList));
            }else{
                List<QuestionExtInfo> questionExtInfoList = converListModel(null , 0);
                model.addAttribute("data" , new Gson().toJson(questionExtInfoList));
                model.addAttribute("count" , 0);
            }
        return "ehm/question/lb_edit";
    }


    private QuestionExt converModel(List<EhmProblemRecord> ehmProblemRecordList){
        QuestionExt ext = new QuestionExt();
        if(null!=ehmProblemRecordList && ehmProblemRecordList.size()>0){

            List<String> list1 = new ArrayList<>();
            List<String> list2 = new ArrayList<>();
            List<String> list3 = new ArrayList<>();
            for (EhmProblemRecord record : ehmProblemRecordList){
                if(record.getSortId() == 1){
                    ext.setSex(com.aijk.commons.utils.Utils.toInteger(record.getContent()));
                }

                if(record.getSortId() == 2){
                    ext.setAge(com.aijk.commons.utils.Utils.toInteger(record.getContent()));
                }

                if(record.getSortId() == 3){
                    ext.setHeight(record.getContent());
                }

                if(record.getSortId() == 4){
                    ext.setWeight(record.getContent());
                }

                if(record.getSortId() == 5){
                    list1.add(record.getContent());
                }

                if(record.getSortId() == 6){
                    ext.setDl(com.aijk.commons.utils.Utils.toInteger(record.getContent()));
                }

                if(record.getSortId() == 7){
                    ext.setStzk(com.aijk.commons.utils.Utils.toInteger(record.getContent()));
                }

                if(record.getSortId() == 8){
                    list2.add(record.getContent());
                }

                if(record.getSortId() == 9){
                    list3.add(record.getContent());
                }

                if(record.getSortId() == 10){
                    ext.setJkzjhd(com.aijk.commons.utils.Utils.toInteger(record.getContent()));
                }

                if(record.getSortId() == 11){
                    ext.setSfmy(com.aijk.commons.utils.Utils.toInteger(record.getContent()));
                }

                if(record.getSortId() == 12){
                    ext.setYj(record.getContent());
                }
            }
            ext.setQx(list1);
            ext.setJkcj(list2);
            ext.setLjzs(list3);
        }

        return ext;
    }

    private List<QuestionExtInfo> converListModel(List<EhmProblemRecord> ehmProblemRecordList , Integer count){
        QuestionUtils questionUtils = new QuestionUtils();
        List<QuestionExtInfo> questionExtInfoList = questionUtils.converQuestionExtInfo();

        if(null!=ehmProblemRecordList && ehmProblemRecordList.size()>0){
            for (EhmProblemRecord record : ehmProblemRecordList){
                if(record.getSortId() == 1){
                    questionExtInfoList.get(0).getItems().get(com.aijk.commons.utils.Utils.toInteger(record.getContent())).setNo(questionExtInfoList.get(0).getItems().get(com.aijk.commons.utils.Utils.toInteger(record.getContent())).getNo()+1);
                }

                if(record.getSortId() == 2){
                    questionExtInfoList.get(1).getItems().get(com.aijk.commons.utils.Utils.toInteger(record.getContent())).setNo(questionExtInfoList.get(1).getItems().get(com.aijk.commons.utils.Utils.toInteger(record.getContent())).getNo()+1);
                }

                if(record.getSortId() == 5){
                    questionExtInfoList.get(2).getItems().get(com.aijk.commons.utils.Utils.toInteger(record.getContent())).setNo(questionExtInfoList.get(2).getItems().get(com.aijk.commons.utils.Utils.toInteger(record.getContent())).getNo()+1);
                }

                if(record.getSortId() == 6){
                    questionExtInfoList.get(3).getItems().get(com.aijk.commons.utils.Utils.toInteger(record.getContent())).setNo(questionExtInfoList.get(3).getItems().get(com.aijk.commons.utils.Utils.toInteger(record.getContent())).getNo()+1);
                }

                if(record.getSortId() == 7){
                    questionExtInfoList.get(4).getItems().get(com.aijk.commons.utils.Utils.toInteger(record.getContent())).setNo(questionExtInfoList.get(4).getItems().get(com.aijk.commons.utils.Utils.toInteger(record.getContent())).getNo()+1);
                }

                if(record.getSortId() == 8){
                    questionExtInfoList.get(5).getItems().get(com.aijk.commons.utils.Utils.toInteger(record.getContent())).setNo(questionExtInfoList.get(5).getItems().get(com.aijk.commons.utils.Utils.toInteger(record.getContent())).getNo()+1);
                }

                if(record.getSortId() == 9){
                    questionExtInfoList.get(6).getItems().get(com.aijk.commons.utils.Utils.toInteger(record.getContent())).setNo(questionExtInfoList.get(6).getItems().get(com.aijk.commons.utils.Utils.toInteger(record.getContent())).getNo()+1);
                }

                if(record.getSortId() == 10){
                    questionExtInfoList.get(7).getItems().get(com.aijk.commons.utils.Utils.toInteger(record.getContent())).setNo(questionExtInfoList.get(7).getItems().get(com.aijk.commons.utils.Utils.toInteger(record.getContent())).getNo()+1);
                }

                if(record.getSortId() == 11){
                    questionExtInfoList.get(8).getItems().get(com.aijk.commons.utils.Utils.toInteger(record.getContent())).setNo(questionExtInfoList.get(8).getItems().get(com.aijk.commons.utils.Utils.toInteger(record.getContent())).getNo()+1);
                }
            }
            for (QuestionExtInfo info : questionExtInfoList){
                for (QuestionExtInfo.QestionInfoItem item : info.getItems()){
                    Float a = Utils.toFloat(item.getNo());
                    Float b = Utils.toFloat(count);
                    Float c = (a/b) * 100;
                    item.setPercentile(String.format("%.1f", c));
                }
            }
        }
        return questionExtInfoList;
    }

    /** 检测报告word导出 **//*
    @RequestMapping(value = "/downWord", method = RequestMethod.GET)
    public RetMsg downReport(Long companyId,
                           HttpServletRequest request, HttpServletResponse response) {
        RetMsg retMsg = new RetMsg();
        PrintWriter out = null;
        InputStream is = null;
//        ServletOutputStream os = null;
        OutputStream os = null;
        List<QuestionExtInfo> questionExtInfoList = null;
        try {
            Integer count = 0;
            EhmProblemLogQo ehmProblemLogQo = new EhmProblemLogQo();
            ehmProblemLogQo.setRidIsNotNull("1");
            if(isSubCompany()){
                ehmProblemLogQo.setCompanyId(getCurrentUser().getCompanyId());
            }else{
                EhmCompanyQo ehmCompanyQo = new EhmCompanyQo();
                ehmCompanyQo.setStatus((byte)10);
                List<EhmCompanyVo> ehmCompanyVoList = ehmCompanyApi.list(ehmCompanyQo);
                if(companyId!=null && companyId != Utils.toLong(0)){
                    ehmProblemLogQo.setCompanyId(companyId);
                }else{
                }
            }
            List<EhmProblemLog> ehmProblemLogList = ehmProblemLogApi.list(ehmProblemLogQo);
            if(ehmProblemLogList != null && ehmProblemLogList.size() > 0) {
                List<Long> inIds = new ArrayList<>();
                for (EhmProblemLog log : ehmProblemLogList){
                    inIds.add(log.getId());
                }
                EhmProblemRecordQo ehmProblemRecordQo = new EhmProblemRecordQo();
                ehmProblemRecordQo.setInPid(inIds);
                List<EhmProblemRecord> ehmProblemRecordList = ehmProblemRecordApi.list(ehmProblemRecordQo);
                questionExtInfoList = converListModel(ehmProblemRecordList , ehmProblemLogList.size());
                count = ehmProblemLogList.size();
            }else{
                retMsg.put("code" , 0);
                retMsg.put("msg" , "无数据");
                return  retMsg;
            }

            String body = this.getAllHtml(questionExtInfoList, count);

            // 生成下载文件名
            String fileName = "问卷列表统计";

            byte b[] = body.getBytes("utf-8");  //这里是必须要设置编码的，不然导出中文就会乱码。
            ByteArrayInputStream bais = new ByteArrayInputStream(b);//将字节数组包装到流中

            POIFSFileSystem poifs = new POIFSFileSystem();
            DirectoryEntry directory = poifs.getRoot();
            DocumentEntry documentEntry = directory.createDocument("WordDocument", bais);
            //输出文件
            request.setCharacterEncoding("utf-8");
            response.setContentType("application/msword");//导出word格式
            response.addHeader("Content-Disposition", "attachment;filename=" +
                    new String( (fileName + ".doc").getBytes(),
                            "iso-8859-1"));

            OutputStream ostream = response.getOutputStream();
            poifs.writeFilesystem(ostream);
            bais.close();
            ostream.close();
            return  retMsg;
        } catch (Exception e) {
            try {
                out = response.getWriter();
                out.println("<script>alert(\"下载失败！\");\r\n window.close();</script>");
            } catch (IOException ee) {
                ee.printStackTrace();
            }
        } finally {
            try {
                if (is != null) is.close();
                if (os != null) os.close();
            } catch (IOException ex) {
                ex.printStackTrace();
                return RetMsg.failed();
            }
        }
        return retMsg;
    }*/

    /** 检测报告pdf导出 **/
    @RequestMapping(value = "/downPDF", method = RequestMethod.POST)
    @ResponseBody
    public RetMsg downReport(Long companyId,
                             HttpServletRequest request, HttpServletResponse response) {
        RetMsg retMsg = new RetMsg();
        List<QuestionExtInfo> questionExtInfoList = null;
        String pathurl = request.getServletContext().getRealPath("") /*+ "download/"*/;
        String fileName = "question.pdf"; //模板名称
        try {
            Integer count = 0;
            EhmProblemLogQo ehmProblemLogQo = new EhmProblemLogQo();
            ehmProblemLogQo.setRidIsNotNull("1");
            if(isSubCompany()){
                ehmProblemLogQo.setCompanyId(getCurrentUser().getCompanyId());
            }else{
                EhmCompanyQo ehmCompanyQo = new EhmCompanyQo();
                ehmCompanyQo.setStatus((byte)10);
                List<EhmCompanyVo> ehmCompanyVoList = ehmCompanyApi.list(ehmCompanyQo);
                if(companyId!=null && companyId != Utils.toLong(0)){
                    ehmProblemLogQo.setCompanyId(companyId);
                }else{
                }
            }
            List<EhmProblemLog> ehmProblemLogList = ehmProblemLogApi.list(ehmProblemLogQo);
            if(ehmProblemLogList != null && ehmProblemLogList.size() > 0) {
                List<Long> inIds = new ArrayList<>();
                for (EhmProblemLog log : ehmProblemLogList){
                    inIds.add(log.getId());
                }
                EhmProblemRecordQo ehmProblemRecordQo = new EhmProblemRecordQo();
                ehmProblemRecordQo.setInPid(inIds);
                List<EhmProblemRecord> ehmProblemRecordList = ehmProblemRecordApi.list(ehmProblemRecordQo);
                questionExtInfoList = converListModel(ehmProblemRecordList , ehmProblemLogList.size());
                count = ehmProblemLogList.size();
            }else{
                retMsg.put("code" , 0);
                retMsg.put("msg" , "无数据");
                return  retMsg;
            }

            String fontPath = "";
            String os = System.getProperties().getProperty("os.name");
            if (os.startsWith("win") || os.startsWith("Win")) {
                fontPath = request.getServletContext().getRealPath("\\WEB-INF\\static\\inspinia\\fonts\\simkai.ttf");
            } else {
                fontPath = "/usr/share/fonts/chinese/simkai.ttf";
            }
//            System.out.println(fontPath);
            String filePath =new String( pathurl+fileName);
            PdfUtils.dowmPDF(filePath , fontPath , questionExtInfoList , count);
            retMsg.put("code" , 0);
            retMsg.put("path", request.getScheme() + "://" + request.getServerName()
                    + ":" + request.getServerPort()
                    + "/"
                    + fileName);
            return  retMsg;
        } catch (Exception e) {
            e.printStackTrace();
            retMsg.put("code" , -1);
            retMsg.put("msg" , "导出错误");
            return  retMsg;
        }
    }


    private String getAllHtml(List<QuestionExtInfo> questionExtInfoList, Integer count) {
        StringBuffer strb = new StringBuffer();
        String style = "border-top: 2px solid black; margin-top: 10px; "
                + "border-bottom: 2px solid black; font-size: 16px; height: 25px;";

        strb.append("<div style=\"background-color: white; padding: 10px 20px;\">")
                .append("    <table style=\"height: 30px; width: 100%;\">")
                .append("        <thead>")
                .append("        <tr>")
                .append("        <th class=\"col-md-4\">调查问卷</th>")
                .append("         <th class=\"col-md-1\">调查人数</th>")
                .append("        <th class=\"col-md-3\">可选项</th>")
                .append("        <th class=\"col-md-2\">数量</th>")
                .append("        <th class=\"col-md-2\">占比(%)</th>")
                .append("        </tr>")
                .append("        </thead>")
                .append("         <tbody >")
                .append(getContent(questionExtInfoList , count))
                .append("        </tbody>")
                .append("    </table>")
                .append("</div>");
        return strb.toString();
    }

    private String getContent(List<QuestionExtInfo> questionExtInfoList, Integer count){
        String content = "";
        for (Integer n = 0 ; n < questionExtInfoList.size() ; n++) {
            if(n == 0){
                content += "<tr><td colspan='5' class='colspan-title'>基本信息</td></tr>";
            }
            if(n == 2){
                content += "<tr><td colspan='5' class='colspan-title'>个人现状 (可多选)</td></tr>";
            }
            if(n == 4){
                content += "<tr><td colspan='5' class='colspan-title'>健康企业创建意见和建议</td></tr>";
            }
            List<QuestionExtInfo.QestionInfoItem> itemData = questionExtInfoList.get(n).getItems();
            Integer itemLenth = itemData.size();
            content+="<tr>"+
                    "<td rowspan='"+itemLenth+"' class='text-style'>"+questionExtInfoList.get(n).getTitle()+"</td>"+
                    "<td rowspan='"+itemLenth+"' class='text-style'>"+count+"</td>";

            for (Integer j = 0 ; j<itemData.size() ; j++) {
                if(j!=0){
                    content+="<tr>";
                }
                content+="<td>"+itemData.get(j).getTitle()+"</td>"+
                        "<td>"+itemData.get(j).getNo()+"</td>"+
                        "<td>"+itemData.get(j).getPercentile()+"%</td>"+
                        " </tr>";
            }

        }
        return content;
    }


    public static  void test1(){
        
    }

}
